// ActionScript file
package vivek.project.pocketmoney.common.logger
{
	import mx.logging.ILogger;
	import mx.logging.Log;
	import mx.logging.LogEventLevel;
	import mx.utils.ObjectUtil;

	public class PMLogger
	{
		private static var logger:ILogger=null;
		private static var logs:Array=new Array();
		private static const messageTemplate:String="{0}\t{1}\t{2}\n";
		private static var pmTarget:PMLogTarget=new PMLogTarget();
		private static var fileTarget:FileTarget=new FileTarget();
		public static function flush():int
		{
			var count:int=0;
			var obj:Object=new Object();
			if (logger == null)
			{
				logger=Log.getLogger("vivek.project.pocketmoney");
				Log.addTarget(new PMLogTarget());
				pmTarget.filters["vivek.project.pocketmoney.*"];
			}
			for each (obj in logs)
			{
				logger.log(LogEventLevel.INFO, messageTemplate, obj);
				count++;
			}
			logs=new Array();
			return count;
		}
		public static function log(module:String, message:String, obj:Object):void
		{
			if (logger == null)
			{
				logger=Log.getLogger("vivek.project.pocketmoney");
				//Log.addTarget(new PMLogTarget());
				Log.addTarget(fileTarget);
				pmTarget.filters["vivek.project.pocketmoney.*"];
			}
			var objInfo:Object=ObjectUtil.getClassInfo(obj,["mx_internal_uid"]);
			var properties:String="";
			for each (var qName:QName in objInfo.properties)
				properties=properties + "," + qName.localName + "=" + obj[qName.localName];
			logger.log(LogEventLevel.INFO, messageTemplate, module, message, properties);
		}
		public static function logMisc(module:String, message:String, misc:String):void
		{
			if (logger == null)
			{
				logger=Log.getLogger("vivek.project.pocketmoney");
				//Log.addTarget(new PMLogTarget());
				Log.addTarget(fileTarget);
				pmTarget.filters["vivek.project.pocketmoney.*"];
			}
			logger.log(LogEventLevel.INFO, messageTemplate, module, message, null, misc);
		}
		public static function logMultiple(module:String, message:String, obj:Object):void
		{
		//	var obj:Object=new Object();
			log(module,message,obj);
			//obj.message=message
			//obj.txnId=txnId
			//obj.account=account
			//obj.amount=amount;
			//obj.expDate=expDate;
			//obj.transferAccount=transferAccount;
			//obj.category=category;
			//logs.push(obj);
		}
		public function PMLogger()
		{
			//	Log.addTarget(new PMLogTarget());
			Log.addTarget(fileTarget);
			pmTarget.filters["vivek.project.pocketmoney.*"];
		}
	}
}